package org.example.dataobject;

import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xietl
 * @date 2025/10/28  14:47
 * @description 前缀树的实体类
 */
@Data
public class TrieNode {
    //子节点映射，键为字符，值为子节点
    private Map<Character,TrieNode> children;
    //是否为单词的结束节点
    private boolean isEndOfWord;
    //存储以该节点为结尾的单词的索引列表
    private List<Integer> wordIndices;

    public TrieNode(){
        children = new HashMap<>();
        isEndOfWord = false;
        wordIndices = new ArrayList<>();
    }

    public List<Integer> getItemIds() {
        return wordIndices;
    }

    public void addItem(Integer itemId) {
        if (!wordIndices.contains(itemId)) {
            wordIndices.add(itemId);
        }
    }

}
